<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let p = new Promise((resolve, reject) => {//处理异步操作
      setTimeout(() => {
        //resolve('成功')
        reject('失败')
      }, 2000)
    })

    async function pA() {
      await p.then(res => {
        return res
      }).catch(err => {
        return err
      })
    }
    let resultpA = pA()
    //console.log(resultpA);

    //高级用法2:
    //口诀:then()里函数体里的return,返回给下一个Promise对象的then里使用
    //情况1:return 的是非Promise对象
    /*  let pB = p.then(res => {//res:'成功'
       console.log(res);
       //替换掉原来的成功结果
       return new Promise((resolve, reject) => {//处理异步操作
         setTimeout(() => {
           resolve('成功la')
         }, 2000)
       })
       // return 1000//特殊:return给pB(下一个Promise对象的then里使用)
     }) */

    /*  pB.then(result => {
       console.log(result);
     }) */
    //情况2:return的是一个promise对象呢?
  </script>
</body>

</html>